package com.itheima.mapper;

import com.itheima.pojo.Ecometeorology;
import com.itheima.pojo.Flux;
import com.itheima.pojo.Meteorology;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface EcometeorologyMapper {

    // 插入数据
    @Insert("insert into ecometeorology (timestamp, record, battVoltMin, PTemp, PM2Point5, PM10, TSP, PMTemp, PMRH," +
            " PMStatus, WSWVc1, WSWVc2, WSWVc3, CO2Avg, eAvg, TempAvg, RHAvg, BPAvg ) " +
            "values (#{timestamp}, #{record}, #{battVoltMin}, #{PTemp}, #{PM2Point5}, #{PM10}, #{TSP}, #{PMTemp}, #{PMRH}" +
            ", #{PMStatus}, #{WSWVc1}, #{WSWVc2}, #{WSWVc3}, #{CO2Avg}, #{eAvg}, #{TempAvg}, #{RHAvg}, #{BPAvg})")
    void add(Ecometeorology ecometeorology);

//    // 查询数据，根据TimeStamp
    @Select("select * from ecometeorology where timestamp = #{timestamp}")
    Ecometeorology findEcometeorologyByTimestamp(LocalDateTime timestamp);

    // 查询数据，返回在TimeStamp在startTime到EndTime之间的所有数据
    @Select("select * from ecometeorology where timestamp between #{startTime} and #{endTime}")
    List<Ecometeorology> findEcometeorologyByTimeRange(LocalDateTime startTime, LocalDateTime endTime);

    // 查询数据库中现有数据的最新日期的当天的全部数据
    @Select("select * from ecometeorology where date(timestamp) = (select max(date(timestamp)) from ecometeorology)")
    List<Ecometeorology> findEcometeorologyInLatestDayData();

    // 查询默认时间戳最新的数据
    @Select("SELECT * FROM ecometeorology ORDER BY timestamp DESC LIMIT 1")
    Ecometeorology findLatestEcometeorology();

}
